Skip to content

[3.10] gh-149079: Fix O(n^2) canonical ordering in unicodedata.normalize() (GH-149080) (GH-150843) - #155159

Merged
pablogsal merged 2 commits into
python:3.10from
miss-islington:backport-d3ab945-3.10
Aug 10, 2026
Merged

[3.10] gh-149079: Fix O(n^2) canonical ordering in unicodedata.normalize() (GH-149080) (GH-150843)#155159
pablogsal merged 2 commits into
python:3.10from
miss-islington:backport-d3ab945-3.10

Conversation

@miss-islington

@miss-islington miss-islington commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Replace the insertion sort used for canonical ordering of combining
characters with a hybrid approach: insertion sort for short runs (< 20)
and counting sort for longer runs, reducing worst-case complexity from
O(n^2) to O(n). This prevents denial of service via crafted Unicode
strings with many combining characters in alternating CCC order.

(cherry picked from commit 991224b)
(cherry picked from commit d3ab945)

Co-authored-by: Petr Viktorin [email protected]
Co-authored-by: Seth Larson [email protected]
Co-authored-by: ch4n3-yoon [email protected]
Co-authored-by: Seokchan Yoon [email protected]
Co-authored-by: Stan Ulbrych [email protected]
Co-authored-by: Bénédikt Tran [email protected]
Co-authored-by: Serhiy Storchaka [email protected]
Co-authored-by: Maurycy Pawłowski-Wieroński [email protected]

…normalize() (pythonGH-149080) (pythonGH-150843)

Replace the insertion sort used for canonical ordering of combining
characters with a hybrid approach: insertion sort for short runs (< 20)
and counting sort for longer runs, reducing worst-case complexity from
O(n^2) to O(n). This prevents denial of service via crafted Unicode
strings with many combining characters in alternating CCC order.

(cherry picked from commit 991224b)
(cherry picked from commit d3ab945)

Co-authored-by: Petr Viktorin <[email protected]>
Co-authored-by: Seth Larson <[email protected]>
Co-authored-by: ch4n3-yoon <[email protected]>
Co-authored-by: Seokchan Yoon <[email protected]>
Co-authored-by: Stan Ulbrych <[email protected]>
Co-authored-by: Bénédikt Tran <[email protected]>
Co-authored-by: Serhiy Storchaka <[email protected]>
Co-authored-by: Maurycy Pawłowski-Wieroński <[email protected]>
@pablogsal
pablogsal merged commit db744c0 into python:3.10 Aug 10, 2026
14 of 15 checks passed
@miss-islington
miss-islington deleted the backport-d3ab945-3.10 branch August 10, 2026 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants